<template>
  <div class='container'>
    <questionSselect></questionSselect>
    <el-alert
      v-if="alertText !== ''"
      :title="alertText"
      type="info"
      class="alert"
      :closable="false"
      show-icon
    ></el-alert>
    <el-table
        :data="dataList"
        stripe
        style="width: 100%">
        <el-table-column
          prop="number"
          label="试题编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="subject"
          label="学科"
          width="180">
        </el-table-column>
        <el-table-column
          prop="catalog"
          label="目录">
        </el-table-column>
        <el-table-column
          prop="question"
          v-slot="{row}"
          label="题干">
          <p v-html="row.question"></p>
        </el-table-column>
        <el-table-column
          prop="addDate"
          v-slot="{row}"
          width="180"
          label="录入时间">
          {{ row.addDate |  parseTimeByString("{y}-{m}-{d} {h}:{i}:{s}")}}
        </el-table-column>
        <el-table-column
          prop="difficulty"
          v-slot="{row}"
          label="难度">
          {{ row.difficulty | toDifficult }}
        </el-table-column>
        <el-table-column
          prop="creator"
          label="录入人">
        </el-table-column>
        <el-table-column
          label="操作">
        </el-table-column>
     </el-table>
        <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="stParameters.page"
      :page-sizes="[5,10]"
      :page-size="stParameters.pagesize"
      layout="total,  prev, pager, next, sizes,jumper"
      :total="stParameters.total">
    </el-pagination>
  </div>
</template>

<script>
import PageTool from '../../module-manage/components/page-tool.vue'
import { list } from '../../api/hmmm/questions'
import { toDifficult,parseTimeByString } from '../../filters/index'
import questionSselect from '../components/questions-select'
export default {
  name: 'QuestionsIndex',
    data() {
      return {
        total: null,
        alertText:'',
        dataList: [],  //基础题库列表
        stParameters: {
          page: 1,
          pagesize: 100,
          total: 0
          },
      }
    },
  components:{
    questionSselect,
    PageTool
  }
  ,
  created(){
    this.getList()  //获取基础题库列表


  },
  methods:{
    async getList(){  //获取基础题库列表
      const { data: res } = await list(this.stParameters)
      // console.log(res)
      this.dataList = res.items
      console.log(this.dataList)
      this.stParameters.total = this.dataList.length
      console.log(this.dataList)
      this.alertText = `共 ${this.dataList.length} 条记录`
      // console.log(this.alertText)
    },
      handleSizeChange(val) {
        this.stParameters.pagesize = val
        console.log(`每页 ${val} 条`);
        this.getList()
      },
      handleCurrentChange(val) {
       this.stParameters.page = val
        // console.log(`当前页: ${val}`);
        this.getList()

      }

  },
}
</script>

<style scoped lang='less'>
.container{
  background-color: #fff;
}
 .alert {
  margin: 10px 0px;
}
</style>
